package com.zz.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zz.dao.HouRentMapper;
import com.zz.dto.HouRentDto;
import com.zz.dto.PageDto;
import com.zz.pojo.HouRent;
import com.zz.pojo.HouRentExample;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class HouRentServiceImpl implements HouRentService {
    @Autowired
    private HouRentMapper houRentMapper;


    @Override
    public int addHouRen(HouRentDto dto) {
        return 0;
    }

    @Override
    public int delHouRent(Long id) {
        return 0;
    }

    @Override
    public int updateHouRent(HouRentDto dto) {
        return 0;
    }

    @Override
    public HouRentDto findById(Long id) {
        return null;
    }

    @Override
    public List<HouRentDto> findByPage(PageDto pageDto) {
        List<HouRentDto> list =new ArrayList<>();
        PageHelper.startPage(pageDto.getCurrentPage(), pageDto.getSize());
        HouRentExample example=new HouRentExample();
        List<HouRent> pojolist = houRentMapper.selectByExample(example);
        PageInfo pageInfo=new PageInfo(pojolist);
        //获取记录数
        long total = pageInfo.getTotal();
        //获取总页数
        int MaxPage = pageInfo.getPages();
        //将总页数放入pagedto
        pageDto.setMaxPage(MaxPage);

        for (HouRent pojo : pojolist) {
            HouRentDto dto=new HouRentDto();
            BeanUtils.copyProperties(pojo,dto);
            list.add(dto);
        }
        return list;
    }
}
